package com.hkg.springcloud.controller;

import com.hkg.springcloud.entities.CommonResult;
import com.hkg.springcloud.entities.Payment;
import com.hkg.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName : PaymentController
 * @Author : huaikaigang
 * @Date: 2020-07-27 11:24
 * @类描述:
 */
@RestController
@Slf4j
public class PaymentController {
    @Autowired
    private PaymentService paymentService;

    @PostMapping(value = "/payment/create")
    public CommonResult create(@RequestBody Payment payment) {
        int i = paymentService.create(payment);
        if (i > 0) {
            return new CommonResult<>(00, "添加成功！", payment);
        } else {
            return new CommonResult<Payment>(01, "添加失败！");
        }
    }

    @GetMapping(value = "/payment/get/{id}")
    public CommonResult get(@PathVariable("id") Long id) {
        Payment paymentById = paymentService.getPaymentById(id);
        if (paymentById == null) {
            return new CommonResult<>(01, "查询失败", null);
        }
        return new CommonResult<>(00, "查询成功", paymentById);


    }
}
